﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.Plumbing
{
	public partial class FormModelAnalyse : System.Windows.Forms.Form
	{
		public FormModelAnalyse()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Location = new Point(100, 100);
			//base.Icon = Resource.YArchitechIcon;
		}

		protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
		{
			int num = 256;
			int num2 = 260;
			if ((msg.Msg == num | msg.Msg == num2) && keyData == Keys.Escape)
			{
				base.DialogResult = DialogResult.Cancel;
			}
			return false;
		}

		public FormModelAnalyse(string volume, string height, string buildingType, string dangerLevel)
		{
			this.InitializeComponent();
			base.Icon = (base.Icon = Resource.YArchitechIcon);
			this.InitBuildingInfo(volume, height);
			this.InitComboBox(buildingType, dangerLevel);
		}

		private void InitComboBox(string buildingType, string dangerLevel)
		{
			if (dangerLevel == null)
			{
				this.comb_DangerLevel.SelectedIndex = 0;
			}
			else
			{
				this.comb_DangerLevel.SelectedItem = dangerLevel;
			}
			foreach (string text in HYCalSQLData.GetBuildingTypes())
			{
				if (!this.comb_BuildingType.Items.Contains(text))
				{
					this.comb_BuildingType.Items.Add(text);
				}
			}
			if (buildingType == null)
			{
				this.comb_BuildingType.SelectedIndex = 0;
				return;
			}
			this.comb_BuildingType.SelectedItem = buildingType;
		}

		private void InitBuildingInfo(string volume, string height)
		{
			if (volume != null)
			{
				this.txt_Volume.Text = volume;
			}
			else
			{
				this.txt_Volume.Text = "0";
			}
			if (height != null)
			{
				this.txt_Height.Text = height;
				return;
			}
			this.txt_Height.Text = "0";
		}

		private void btn_confirm_Click(object sender, EventArgs e)
		{
			if (!this.isNumberic(this.txt_Height.Text))
			{
				YJKMessageBox.Show("建筑总高度必须为数字！");
				return;
			}
			this.buildingHeight = Convert.ToInt32(this.txt_Height.Text);
			if (this.isNumberic(this.txt_Volume.Text))
			{
				this.buildingVolume = Convert.ToInt32(this.txt_Volume.Text);
				this.dangerLevel = this.comb_DangerLevel.Text;
				this.buildingType = this.comb_BuildingType.Text;
				base.DialogResult = DialogResult.OK;
				return;
			}
			YJKMessageBox.Show("建筑总体积必须为数字！");
		}

		private void btn_cancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		protected bool isNumberic(string message)
		{
			bool result;
			try
			{
				Convert.ToInt32(message);
				result = true;
			}
			catch
			{
				result = false;
			}
			return result;
		}

		public int buildingVolume { get; set; }

		public int buildingHeight { get; set; }

		public string dangerLevel { get; set; }

		public string buildingType { get; set; }
	}
}
